﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using BudgetMealsUI.Models;
using System.Text;

namespace BudgetMealsUI.Helpers
{
    public static class PagingHelpers
    {
        public static MvcHtmlString PageLinks(this HtmlHelper h, PagingInfo info, Func<int, String> pageUrl)
        {
            StringBuilder links = new StringBuilder();
            for (int i = 1; i <= info.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                if (i == info.CurrentPage)
                {
                    tag.AddCssClass("selected");
                }
                tag.InnerHtml = i.ToString();
                links.Append(tag.ToString());
            }
            return MvcHtmlString.Create(links.ToString());
        }
    }
}